﻿
Imports Microsoft.VisualBasic

Public Class clsCheckPwd
    Private strMsg As String = ""

    Public ReadOnly Property Msg() As String
        Get
            Return strMsg
        End Get
    End Property

    Function checkpassword(ByVal pReceivePassword As String) As Boolean
        Dim i, TheNumber As Integer
        Dim x As String = ""
        Dim find As Boolean = False
        Dim bit1 As Boolean = False
        Dim bit2 As Boolean = False
        Dim bit3 As Boolean = False
        Dim bit4 As Boolean = False

        For i = 1 To Len(pReceivePassword)
            find = False
            x = Mid(pReceivePassword, i, i)
            TheNumber = Asc(x)

            If TheNumber >= Asc("a") And TheNumber <= Asc("z") Then
                bit1 = True
            End If

            If TheNumber >= Asc("A") And TheNumber <= Asc("Z") Then
                bit2 = True
            End If

            If TheNumber >= Asc("0") And TheNumber <= Asc("9") Then
                bit3 = True
            End If

            If (TheNumber >= Asc("!") And TheNumber <= Asc("/")) Or TheNumber >= Asc(":") And TheNumber <= Asc("@") Or TheNumber >= Asc("[") And TheNumber <= Asc("_") Or TheNumber >= Asc("{") And TheNumber <= Asc("~") Then
                bit4 = True
            End If

            If bit1 And bit2 And bit3 And bit4 Then
                find = True
                Exit For
            End If

        Next

        If Not (bit1 = True) Then
            strMsg = strMsg & "ขาดตัวอักษรตัวพิมพ์เล็ก"
        End If
        If Not (bit2 = True) Then
            If (strMsg = "") Then
                strMsg = strMsg & "ขาดตัวอักษรตัวใหญ่"
            Else
                strMsg = strMsg & " , " & "ขาดตัวอักษรตัวใหญ่"
            End If

        End If
        If Not (bit3 = True) Then
            If (strMsg = "") Then
                strMsg = strMsg & "ขาดตัวเลข"
            Else
                strMsg = strMsg & " , " & "ขาดตัวเลข"
            End If

        End If
        If Not (bit4 = True) Then
            If (strMsg = "") Then
                strMsg = strMsg & "ขาดอักขระพิเศษ"
            Else
                strMsg = strMsg & " , " & "ขาดอักขระพิเศษ"
            End If

        End If

        If Len(pReceivePassword) < 8 Then
            If (strMsg = "") Then
                strMsg = strMsg & "ความยาวต้องมากกว่า 8 ตัวอักษร "
            Else
                strMsg = strMsg & " , " & "ความยาวต้องมากกว่า 8 ตัวอักษร "
            End If
            find = False
        End If
        Return find
    End Function
End Class
